package com.ziyun.erp.modules.goodsConfigChangePrice.service.impl;

import com.utility.StringUtils;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.StringUtil;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.goodsConfigChangePrice.dao.GoodsConfigChangePriceDao;
import com.ziyun.erp.modules.goodsConfigChangePrice.entity.GoodsConfigChangePriceEntity;
import com.ziyun.erp.modules.goodsConfigChangePrice.service.GoodsConfigChangePriceService;


@Service("goodsConfigChangePriceService")
public class GoodsConfigChangePriceServiceImpl extends ServiceImpl<GoodsConfigChangePriceDao, GoodsConfigChangePriceEntity> implements GoodsConfigChangePriceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Integer productId = StringUtil.getRequestParamInteger(params.get("productId"));
        String goodsName = StringUtil.getRequestParamString(params.get("goodsName"));
        String changeType = StringUtil.getRequestParamString(params.get("changeType"));
        String status = StringUtil.getRequestParamString(params.get("status"));
        Page<GoodsConfigChangePriceEntity> page = this.selectPage(
                new Query<GoodsConfigChangePriceEntity>(params).getPage(),
                new EntityWrapper<GoodsConfigChangePriceEntity>()
                .eq(productId != null,"sku",productId)//underway all end
                .like(StringUtils.isNotBlank((goodsName)),"goods_name",goodsName)
                .eq(StringUtils.isNotBlank(changeType),"change_type",changeType)
                .addFilterIfNeed(StringUtils.isNotBlank(status) && status.equals("noStart"),"start_time > now()")
                .addFilterIfNeed(StringUtils.isNotBlank(status) && status.equals("underway"),"start_time  <= now() AND end_time  >= now()")
                .addFilterIfNeed(StringUtils.isNotBlank(status) && status.equals("end"),"end_time < now()")
        );

        return new PageUtils(page);
    }

}
